import Vue from 'vue'
import Router from 'vue-router'
import HelloWorld from '@/components/HelloWorld'
import menus from '@/config/menu-config'

Vue.use(Router)

var routes = []
//``模板表达式语法
menus.forEach((item) =>{
  item.sub.forEach((sub) => {
    // sub.nextSub((nextSub) => {
    //   //存放nextsub
    //   routes.push({
    //     path:`/${nextSub.componentName}`,
    //     name: nextSub.componentName,
    //     component: () => import(`@/components/${sub.componentName}/${nextSub.componentName}`)
    //   })
    // })
    //存放next
    routes.push({
      path:`/${sub.componentName}`,
      name: sub.componentName,
      component: () => import(`@/components/${sub.componentName}`)
    })
  })
})
//去掉默认#号 添加 mode 为 history
export default new Router({ routes:routes,
  base: process.env.BASE_URL,
  mode: 'history' })

// export default new Router({
//   routes: [
//     {
//       path: '/',
//       name: 'HelloWorld',
//       component: HelloWorld
//     }
//   ]
// })
